<?php

/**
 * 通过code请求接口获取openid
 * @param $code 用户登录code
 * @return mixed|string
 */
function getOpenid($code){
    $url = 'https://api.weixin.qq.com/sns/jscode2session';
    $appid = "wx711478f195b9f14a";//config('site.appid');
    $secret = "6e7b82d1c9fd206c5cbc8b087770f31d";//cconfig('site.AppSecret');
    $url .= "?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code";
    $result = \fast\Http::get($url);
    return json_decode($result,true);
}

/**
 * 获取accessToken
 * @return mixed
 */
function getAccessToken(){
    $url = "https://api.weixin.qq.com/cgi-bin/token";
    $appid = "wx711478f195b9f14a";
    $secret = "6e7b82d1c9fd206c5cbc8b087770f31d";
    $url .= "?grant_type=client_credential&appid={$appid}&secret={$secret}";
    $result = \fast\Http::get($url);
    return json_decode($result,true);
}